using System.Data;
using Company.BLL.WS.SXXK;

namespace Company.BLL.SXXK
{
    public partial class NguyenPhuLieu
    {
        public DataSet SearchBy_MaHaiQuan(string maHaiQuan)
        {
            string where = string.Format("MaHaiQuan = '{0}'", maHaiQuan.PadRight(6));
            return this.SelectDynamic(where, "Ma");
        }

        public DataSet WS_GetDanhSachDaDangKy(string maHaiQuan, string maDoanhNghiep)
        {
            SXXKService service = new SXXKService();
            return service.NguyenPhuLieu_GetDanhSach(maHaiQuan, maDoanhNghiep);
        }

        public bool UpdateRegistedToDatabase(string maHaiQuan, string maDoanhNghiep, DataSet ds)
        {
            NguyenPhuLieuCollection collection = new NguyenPhuLieuCollection();
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                NguyenPhuLieu npl = new NguyenPhuLieu();
                npl.MaHaiQuan = maHaiQuan;
                npl.MaDoanhNghiep = maDoanhNghiep;
                npl.Ma = row["Ma"].ToString();
                npl.Ten = row["Ten"].ToString();
                npl.MaHS = row["MaHS"].ToString().Trim();
                int k = npl.MaHS.Length;
                if (npl.MaHS.Length < 10)
                {
                    for (int i = 1; i <= 10 - k; ++i)
                        npl.MaHS += "0";
                }
                npl.DVT_ID = row["DVT_ID"].ToString();
                collection.Add(npl);
            }
            NguyenPhuLieu NPL = new NguyenPhuLieu();
            return NPL.InsertUpdate(collection);
        }
    }
}